package com.cskaoyan.controller.wxcontroller;

import com.cskaoyan.bean.bo.WxGoodsListBo;
import com.cskaoyan.bean.pojo.Goods;
import com.cskaoyan.bean.pojo.GoodsBrand;
import com.cskaoyan.bean.pojo.User;
import com.cskaoyan.bean.vo.*;
import com.cskaoyan.service.GoodsService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program:
 * @description:
 * @author: Qian Jin
 * @create: 2021-07-11
 * @detail:
 **/

@RestController
@RequestMapping("wx")
public class WxGoodsController {

    @Autowired
    GoodsService goodsService;

    @GetMapping("goods/count")
    public BaseRespVo getWxGoodsCount() {
        WxGoodsCountVo wxGoodsCountVo = goodsService.getWxGoodsCount();
        return BaseRespVo.ok(wxGoodsCountVo);
    }

    @GetMapping("goods/list")
    public BaseRespVo getWxGoodsList(String keyword, Integer brandId, Integer categoryId,
                                     Integer page, Integer size, String order, String sort) {
        WxGoodsListBo wxGoodsListBo = new WxGoodsListBo();
        wxGoodsListBo.setKeyword(keyword);
        wxGoodsListBo.setOrder(order);
        wxGoodsListBo.setSort(sort);
        wxGoodsListBo.setBrandId(brandId);
        wxGoodsListBo.setPage(page);
        wxGoodsListBo.setCategoryId(categoryId);
        wxGoodsListBo.setSize(size);
        WxGoodsListVo wxGoodsListVo = goodsService.getWxGoodsList(wxGoodsListBo);
        return BaseRespVo.ok(wxGoodsListVo);
    }

    @GetMapping("home/index")
    public BaseRespVo getWxHomeIndex() {
        WxHomeIndexVo wxHomeIndexVo = goodsService.getWxHomeIndex();
        return BaseRespVo.ok(wxHomeIndexVo);
    }

    @GetMapping("catalog/index")
    public BaseRespVo getCatalogIndex() {
        WxCatalogIndexVo wxCatalogIndexVo = goodsService.getCatalogIndex();
        return BaseRespVo.ok(wxCatalogIndexVo);
    }

    @GetMapping("catalog/current")
    public BaseRespVo getCatalogCurrent(Integer id) {
        WxCatalogCurrentVo wxCatalogCurrentVo = goodsService.getCatalogCurrent(id);
        return BaseRespVo.ok(wxCatalogCurrentVo);
    }

    @GetMapping("goods/category")
    public BaseRespVo getGoodsCategory(Integer id) {
        WxGoodsCategoryVo wxGoodsCategoryVo = goodsService.getGoodsCategory(id);
        return BaseRespVo.ok(wxGoodsCategoryVo);
    }

    @GetMapping("brand/detail")
    public BaseRespVo getBrandDetail(Integer id) {
        WxGoodsBrandDetailVo goodsBrand = goodsService.getBrandDetail(id);
        return BaseRespVo.ok(goodsBrand);
    }

    @GetMapping("brand/list")
    public BaseRespVo getBrandList(Integer page, Integer size) {
        WxGoodsBrandListVo goodsBrandList = goodsService.getBrandList(page, size);
        return BaseRespVo.ok(goodsBrandList);

    }

    @GetMapping("goods/detail")
    public BaseRespVo getGoodsDetail(Integer id) {
        WxGoodsDetailVo wxGoodsDetailVo = goodsService.getWxGoodsDetail(id);
        if (wxGoodsDetailVo.getInfo()==null){
            return BaseRespVo.fail("商品已下架！");
        }
        return BaseRespVo.ok(wxGoodsDetailVo);
    }

    @GetMapping("goods/related")
    public BaseRespVo getGoodsRelated(Integer id) {
        WxGoodsRelatedVo goodsList = goodsService.getGoodsRelated(id);
        return BaseRespVo.ok(goodsList);
    }

}
